-module(emqx_modbus_plugin_sup).

-behavior(supervisor).

-export([start_link/4, init/1]).

%% @doc Start modbus device Supervisor.
-spec(start_link(list(), list(), integer(), boolean()) -> {ok, pid()}).
start_link(CompanyName, EdgeName, Qos, Retain) ->
    supervisor:start_link({local, ?MODULE}, ?MODULE, [CompanyName, EdgeName, Qos, Retain]).


init([CompanyName, EdgeName, Qos, Retain]) ->
    {ok, {{one_for_all, 50, 3600},
        [
            {emq_modbus_device_sup, {emq_modbus_device_sup, start_link, []},
                temporary, 5000, worker, [emq_modbus_device_sup]},
            {emq_modbus_control, {emq_modbus_control, start_link, [CompanyName, EdgeName, Qos, Retain]},
                temporary, 5000, worker, [emq_modbus_device]}
        ]}}.